<?php
            
use app\model\Record; 
use app\model\Ad; 
use app\model\Theme; 
use app\model\Worker; 
use app\model\Fans; 
use app\model\Userdata; 





class Index_Page extends PluginMobilePage
{

//获取定位位置下的商家课程信息
    public function GetShangJiaByLg()
    {
        global $_P, $_G;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $page = $_P['page'] ? (int)$_P['page'] : 1;
        $theme = Theme::getThemeById($themeid);
        $user_location = isset($_P['user_location']) ? $_P['user_location'] : '';
        $item = EducationModel::getRewardByWhere(['themeid' => $themeid]);
        $other_config = json_decode($item['other_config'], true);
        $open_position = $other_config['open_position'];
        if ($open_position){
            if (!$user_location) {
                $user_map_loc = EducationModel::getUserMapLoc($themeid, $uid);
                if ($user_map_loc) {
                    $user_location = $user_map_loc['lat_lng'];
                }
            }
        }

        $shangjia_all_list = EducationModel::getShangjiaList();
        foreach ($shangjia_all_list as $sk => $sv) {
            $shangjia_all_list[$sk]['address'] = json_decode($sv['address'], true);
            $shangjia_all_list[$sk]['mappoint'] = json_decode($sv['mappoint'], true);
        }
        //左侧商家课程
        $left_sj_list = $shangjia_all_list;
        $offset = $page - 1;
        $shangjia_list = array_splice($shangjia_all_list, $offset, 10);
        $res = [];

        if ($user_location) {
            foreach ($shangjia_list as $key => $vv) {
                if ($vv['mappoint'] && $vv['address'] && is_array($vv['mappoint'])) {
                    $distance_arr = [];
                    foreach ($vv['mappoint'] as $k1 => $v1) {
                        $distance_item = EducationModel::distance($v1, $user_location);
                        array_push($distance_arr, $distance_item);
                    }
                    $shangjia_list[$key]['min_distance'] = min($distance_arr);
                }
            }
            $sort_filed = array_column($shangjia_list, 'min_distance');
            $shangjia_list = Ad::arraySort($shangjia_list, 'min_distance', 'asc');
        }

        if ($user_location) {
            foreach ($left_sj_list as $key => $vv) {
                if ($vv['mappoint'] && $vv['address'] && is_array($vv['mappoint'])) {
                    $distance_arr = [];
                    foreach ($vv['mappoint'] as $k1 => $v1) {
                        $distance_item = EducationModel::distance($v1, $user_location);
                        array_push($distance_arr, $distance_item);
                    }
                    $left_sj_list[$key]['min_distance'] = min($distance_arr);
                }
            }
            $sort_filed = array_column($left_sj_list, 'min_distance');
            $left_sj_list = Ad::arraySort($left_sj_list, 'min_distance', 'asc');
        }

        //机构视频
        $sj_list = [];
        //机构详情
        $sj_detail_list = [];

        foreach ($shangjia_list as $key => $val) {
            $sj_list_data = ['name' => $val['name'], 'logo' => $val['logo'], 'topimgs' => $val['imgs'],
                'video' => $val['videoyouku'],
                'video_back_img' => $val['video_back_img'] ? $val['video_back_img'] : $val['logo']
            ];
            array_push($sj_list, $sj_list_data);
            //获取机构课程
            $sj_course_list = EducationModel::getCourseList($themeid, $val['id'], '', 0, 0, 1);
            $sj_course_total = EducationModel::getCourseTotal($themeid, $val['id']);
            $sj_xuni_order_total = EducationModel::getSjOrder($val, $themeid);
            if ($sj_course_total > 0) {
                array_push(
                    $sj_detail_list,
                    [
                        'name' => $val['name'], 'logo' => $val['logo'], 'topimgs' => $val['imgs'],
                        'sj_id' => $val['id'],
                        'video' => $val['videoyouku'],
                        'video_back_img' => $val['video_back_img'] ? $val['video_back_img'] : $val['logo'],
                        'content' => $val['content'],
                        'address' => $val['address'],
                        'courses' => $sj_course_list,
                        'min_distance' => $val['min_distance'],
                        'address_total' => count($val['address']),
                        'course_total' => $sj_course_total,
                        'order_total' => $sj_xuni_order_total,
                        'kefu' => ['avatar' => 'https://kaifa5.yixuan.net/storage/shop/20211125/9ea396d559716c614db842d9fbb97670.png', 'mobile' => $val['mobile'], 'name' => $val['name'] . '客服']
                    ]
                );
            }
        }

        //课程展示
        $left_sj_detail_list = [];
        foreach ($left_sj_list as $key => $val) {
            //获取机构课程
            $sj_course_list = EducationModel::getCourseList($themeid, $val['id'], '', 0, 0, 1);
            $sj_course_total = EducationModel::getCourseTotal($themeid, $val['id']);
            $sj_xuni_order_total = EducationModel::getSjOrder($val, $themeid);
            if ($sj_course_total > 0) {
                array_push(
                    $left_sj_detail_list,
                    [
                        'name' => $val['name'], 'logo' => $val['logo'], 'topimgs' => $val['imgs'],
                        'sj_id' => $val['id'],
                        'video' => $val['videoyouku'],
                        'video_back_img' => $val['video_back_img'] ? $val['video_back_img'] : $val['logo'],
                        'content' => $val['content'],
                        'address' => $val['address'],
                        'courses' => $sj_course_list,
                        'min_distance' => $val['min_distance'],
                        'address_total' => count($val['address']),
                        'course_total' => $sj_course_total,
                        'order_total' => $sj_xuni_order_total,
                        'kefu' => ['avatar' => 'https://kaifa5.yixuan.net/storage/shop/20211125/9ea396d559716c614db842d9fbb97670.png', 'mobile' => $val['mobile'], 'name' => $val['name'] . '客服']
                    ]
                );
            }
        }


        $item = EducationModel::getRewardByWhere(['themeid' => $themeid]);
        $other_config = json_decode($item['other_config'], true);
        $school_other_name = $other_config['school_other_name'];
        $course_other_name = $other_config['course_other_name'];
        $gift_other_name = $other_config['gift_other_name'];
        $edu_colors = json_decode($item['colors'], true);
        $show_buy_total = $other_config['show_buy_total'];
        $edu_location_show = $other_config['edu_location_show'];
        $edu_success_location_tips = $other_config['edu_success_location_tips'];

        //课程展示 左侧商家展示排序
        $lessconChoseItems = '';
        foreach ($left_sj_detail_list as $k => $v) {
            if ($k == 0) {
                $lessconChoseItems .= '<span class="cur" data-sjid="' . $v['sj_id'] . '">' . $v['name'] . '</span>';
            } else {
                $lessconChoseItems .= '<span class="" data-sjid="' . $v['sj_id'] . '">' . $v['name'] . '</span>';
            }
        }

        //拼接商家列表
        $sj_detail_list = array_slice($left_sj_detail_list, 0, 5);
        $serviceList = '';
        foreach ($sj_detail_list as $index => $item) {
            $serviceList .= '<li style="background: ' . $edu_colors['shop_item_c'] . '" data-k="" data-sjid="' . $item['sj_id'] . '">' . PHP_EOL;
            $serviceList .= '<div class="serviceImg"><img src="' . $item['logo'] . '" ></div><div class="serviceTxt"><h2>' . $item['name'] . '</h2>';
            $serviceList .= '<p class="phoneNum">' . $item['kefu']['mobile'] . '</p>
                <p class="addInfor">' . $item['address'][0] . '</p>';

            if ($show_buy_total == 2) {
                $serviceList .= '<p style="font-size: .24rem;color: #999999;line-height: .32rem;padding-top: .1rem">已购：' . $item['order_total'] . '</p>';
            }
            if ($user_location) {
                $serviceList .= '<p style="font-size: .24rem;color: #999999;line-height: .32rem;padding-top: .1rem">距离：' . $item['min_distance'] . 'km</p>';
            }
            $serviceList .= '</div><a href="javascript:void(0)" class="checkMore" data-k="' . $index . '" data-sjid="' . $item['sj_id'] . '"
               style="background: linear-gradient(90deg,' . $edu_colors['shop_card_c1'] . " -6.48%," . $edu_colors['shop_card_c2'] . " 97.21%)" . '">查看</a>
                </li>';
        }


        $res = [
            'serviceList' => $serviceList,
            'lessconChoseItems' => $lessconChoseItems,
            'edu_success_location_tips' => $edu_success_location_tips,
            'edu_location_show' => $edu_location_show,
        ];

        return_json(0, '', $res);
    }

//我的
    public function Mine()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $theme = Theme::getThemeById($themeid);
        $_C = $config = Theme::getConfig($themeid);
        $system = $_S;
        $kefu = ['qr_code' => $config['kfewm'], 'mobile' => $theme['mobile']];
        $themyrecord = Record::getLastGroupByUid($fans['uid'], $themeid);
        //海报地址
        extract(EducationModel::Mine($themeid, $system, $config, $fans, $themyrecord));
        //判断存在订单但是不存在合法状态的课程 礼品
        $can_new_select = false;
        if ($themyrecord) {
            //判断是否存在课程记录
            $course_total = (int)EducationModel::getUserCourseTotal($themeid, $themyrecord['id'], $uid);
            $gift_total = (int)EducationModel::getUserGiftTotal($themeid, $themyrecord['id'], $uid);
            if ($course_total < 1 && $gift_total < 1) {
                $can_new_select = true;
            }
        }
        $return_clicent = get_defined_vars();
return $this->view('/education/mine', $return_clicent);
    }

//  预订单确认
    public function PayConfirm()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $theme = Theme::getThemeById($themeid);
        $system = $_S;
        $workerid = $_P['workerid'];
        $_C = $config = Theme::getConfig($themeid);
        $joinid = isset($_P['joinid']) ? $_P['joinid'] : 0;
        $recordid = isset($_P['recordid']) ? $_P['recordid'] : 0;
        $themyrecord = Record::getLastGroupByUid($fans['uid'], $themeid);
        //判断存在订单但是不存在合法状态的课程 礼品
        $can_new_select = false;
        if ($themyrecord) {
            //判断是否存在课程记录
            $course_total = (int)EducationModel::getUserCourseTotal($themeid, $themyrecord['id'], $uid);
            $gift_total = (int)EducationModel::getUserGiftTotal($themeid, $themyrecord['id'], $uid);
            if ($course_total < 1 && $gift_total < 1) {
                $can_new_select = true;
            }
        }
        if ($_G['ispost']) {
            $format_data = EducationModel::PayConfirm($themeid, $theme, $system, $config, $fans, $joinid);
            return_json(0, '', $format_data);
        } else {
            extract(EducationModel::PayConfirm($themeid, $theme, $system, $config, $fans, $joinid));
            $register_jssdk = $this->getJsSdkConfig();
            $return_clicent = get_defined_vars();
            return $this->view('/education/pay_confirm', $return_clicent);
        }
    }

    //补录提交
    public function reloadInfo()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $theme = Theme::getThemeById($themeid);
        $system = $_S;
        $workerid = $_P['workerid'];
        $_C = $config = Theme::getConfig($themeid);
        $themyrecord = Record::getLastGroupByUid($fans['uid'], $themeid);
        if (!$_G['ispost']) {
            return_json(1, '非法请求', []);
            return;
        }
        if (!$themyrecord) {
            return_json(1, '未查询查询到您的定单信息，操作失败', []);
            return;
        }
        $course_address = $_P['course_address'];
        $gift_ids = explode(",", $_P['gift_ids']);
        foreach ($course_address as $key => $val) {
            $course_ids .= $val['courseid'] . ',';
        }
        $course_ids = rtrim($course_ids, ',');
        //删除已存在的用户课程、礼品信息

        //判断用户是否存在礼品选择记录
        $delete_gift = EducationModel::delUserGiftByWhere(['themeid' => $themeid, 'uid' => $uid]);
        //删除用户存在同一订单号的课程选择记录
        $delete_course = EducationModel::deleteUserCourseAddressByWhere(['themeid' => $themeid, 'uid' => $uid]);
        $recordid = $themyrecord['id'];
        //插入礼品
        if ($gift_ids && is_array($gift_ids) && $gift_ids[0]) {
            $log_txt = '用户补录选择礼品:';
            foreach ($gift_ids as $key => $val) {
                $item = EducationModel::getGiftItemById($themeid, $val);
                $data = ['order_id' => $recordid, 'uid' => $uid, 'shangjiaid' => $item['shangjiaid'],
                    'gift_id' => $val, 'status' => 1, 'themeid' => $themeid];
                $res = EducationModel::insertUserGift($data);
                $log_txt .= $item['shangjia_name'] . '(' . $item['name'] . ');';
            }
            Userdata::addLog($themeid, $_G['member']['uid'], 0, $log_txt);
        }
        //插入选择课程以及校区
        $log_txt = '用户补录选择课程:';
        foreach ($course_address as $key => $val) {
            $item = self::getCourseItemById($themeid, $val['courseid']);
            $data = [
                'order_id' => $recordid,
                'uid' => $uid,
                'shangjiaid' => $val['shangjia_id'],
                'course_id' => $val['courseid'],
                'address' => $val['address'],
                'themeid' => $themeid
            ];
            $res = EducationModel::insertUserCourseAddress($data);
            $log_txt .= $item['shangjia_name'] . '(' . $item['name'] . ');';
        }
        Userdata::addLog($themeid, $_G['member']['uid'], 0, $log_txt);
        return_json(0, '提交成功', []);
    }

//  关于我们
    public function About()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $system = $_S;
        $theme = Theme::getThemeById($themeid);
        $_C = $config = Theme::getConfig($themeid);
        $op = isset($_P['op']) ? $_P['op'] : 'display';
        if ($op == 'display') {
            extract(EducationModel::About($themeid, $system, $config, $fans, $op));
            $return_clicent = get_defined_vars();
return $this->view('/education/about', $return_clicent);
        } else {
            $res = EducationModel::About($themeid, $system, $config, $fans, $op);
            return $res;
        }
    }

//  赠品选择
    public function Gift()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $system = $_S;
        $type = $_P['type'];
        $joinid = isset($_P['joinid']) ? $_P['joinid'] : 0;
        $recordid = isset($_P['recordid']) ? $_P['recordid'] : 0;
        $theme = Theme::getThemeById($themeid);
        $_C = $config = Theme::getConfig($themeid);
        extract(EducationModel::Gift($themeid));
        $item = EducationModel::getRewardByWhere(['themeid' => $themeid]);
        $other_config = json_decode($item['other_config'], true);
        $school_other_name = $other_config['school_other_name'];
        $course_other_name = $other_config['course_other_name'];
        $gift_other_name = $other_config['gift_other_name'];
        $canshare = 0;
        $register_jssdk = $this->getJsSdkConfig();
        $return_clicent = get_defined_vars();
        return $this->view('/education/gift', $return_clicent);
    }

//    课程选择
    public function Course()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $theme = Theme::getThemeById($themeid);
        if ($fans['nickname'] == '微信用户' || $fans['nickname'] == '新用户') {
            $workerurl = Fans::get_login_url($_S,$theme);
            //如果员工打开的链接为原始链接则先刷新
            echo "<script language='javascript' type='text/javascript'>";
            echo "window.location.href='$workerurl';";
            echo "</script>";
            exit;
        }
        $fromuid = $_P['fromuid'];
        $system = $_S;
        $_C = $config = Theme::getConfig($themeid);
        $joinid = isset($_P['joinid']) ? $_P['joinid'] : 0;
        $recordid = isset($_P['recordid']) ? $_P['recordid'] : 0;
        $user_location = isset($_P['user_location']) ? $_P['user_location'] : '';
        $user_map_loc_item = EducationModel::getUserMapLoc($themeid, $uid);
        if (!$user_location) {
            $user_location = $user_map_loc_item['lat_lng'];
        }
        extract(EducationModel::Course($themeid, $user_location));
        $item = EducationModel::getRewardByWhere(['themeid' => $themeid]);
        $other_config = json_decode($item['other_config'], true);
        $school_other_name = $other_config['school_other_name'];
        $course_other_name = $other_config['course_other_name'];
        $gift_other_name = $other_config['gift_other_name'];
        $edu_location_img = $other_config['edu_location_img'];
        $edu_location_tips = $other_config['edu_location_tips'];
        $edu_location_tips_font_size = $other_config['edu_location_tips_font_size'];
        $edu_location_tips_color = $other_config['edu_location_tips_color'];
        $edu_location_bg_color = $other_config['edu_location_bg_color'];
        $edu_share_img = $other_config['edu_share_img'];
        $edu_location_show = $other_config['edu_location_show'];
        $open_position = $other_config['open_position'];
        //获取用户定位

        $user_address = '';
        if ($user_map_loc_item) {
            $user_address = $user_map_loc_item['poiaddress'];
        }
         $canshare = 0;
        $jump_map_url = $_G['siteroot'] . createMobileUrl('wx', array('themeid' => $themeid, 'r' => 'education.index.map'));
        $register_jssdk = $this->getJsSdkConfig();
        if ($course_style == 4) {
            //根据课程分类分组显示
            $return_clicent = get_defined_vars();
return $this->view('/education/course4', $return_clicent);
        } elseif ($course_style == 3){
            //根据商家分类分组显示
            $return_clicent = get_defined_vars();
return $this->view('/education/course3', $return_clicent);
        }elseif ($course_style == 2) {
            //根据商家分组显示
            $return_clicent = get_defined_vars();
return $this->view('/education/course2', $return_clicent);
        } else {
            //根据课程显示
            $return_clicent = get_defined_vars();
return $this->view('/education/course', $return_clicent);
        }
    }

//我的奖励
    public function Reword()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $theme = Theme::getThemeById($themeid);
        $_C = $config = Theme::getConfig($themeid);
        $system = $_S;
        $kefu = ['qr_code' => $config['kfewm'], 'mobile' => $theme['mobile']];
        //获取我的奖励  假测试数据
        extract(EducationModel::Reword($themeid, $theme, $system, $fans));
        $return_clicent = get_defined_vars();
return $this->view('/education/reword', $return_clicent);
    }

//    我的课程
    public function MineCourse()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $theme = Theme::getThemeById($themeid);
        $_C = $config = Theme::getConfig($themeid);
        $system = $_S;
        //判断订单状态
        $themyrecord = Record::getLastGroupByUid($fans['uid'], $themeid);
        $kefu = ['qr_code' => $config['kfewm'], 'mobile' => $theme['mobile']];
        extract(EducationModel::MineCourse($themeid, $system, $themyrecord, $fans));
        $return_clicent = get_defined_vars();
return $this->view('/education/mine_course', $return_clicent);
    }

//贝莱核销
    public function Verify()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $system = $_S;
        $themeid = $_P['themeid'];
        $_C = $config = Theme::getConfig($themeid);
        $op = $_P['op'] ? $_P['op'] : 'display';
        $theme = Theme::getThemeById($themeid);
        //判断客服
        $myworker = Worker::getThemeWorkerByOpenid($_G['openid'], $themeid);
        if (!$myworker) {
            if ($_G['ispost']) {
                return_json(1, '非员工无法访问', '');
            }
            return_msg('您无权访问');
            exit;
        } else {
            if ($op == 'diplay') {
//                订单礼品核销

                //判断礼品核销模式
                $setting = EducationModel::getRewardByWhere(['themeid' => $themeid]);
                $other_config = json_decode($setting['other_config'], true);
                $lock_gift_mode = $other_config['lock_gift_mode'];
                $gift_unlock_min_num = $other_config['gift_unlock_min_num'];
                $gift_unlock_max_num = $other_config['gift_unlock_max_num'];

                if ($myworker['level'] < 1 || $myworker['level'] > 3) {
                    return_msg('您无权访问');
                    exit;
                } else {
                    $mobile = $_P['mobile'];
                    if (!$mobile) {
                        return_msg('手机号绑定的订单不存在');
                        exit;
                    }
                    $record_item = db_get(t_record, ['themeid' => $themeid, 'mobile' => $mobile, 'status' => 1]);

                    if (!$record_item) {
                        return_msg('该手机号绑定的订单不存在或未支付');
                        exit;
                    }
                    //判断礼品核销模式
                    if ($lock_gift_mode) {
                        //判断用户已核销的礼品数
                        $verify_gift_total = EducationModel::getUserOrderGiftTotalByWhere($themeid, 2, $record_item['id'], 1);
                        if ($gift_unlock_min_num > 0 && $gift_unlock_max_num > 0) {
                            if ($verify_gift_total > $gift_unlock_max_num) {
                                return_msg('已达到解锁礼品选择数上限');
                                exit;
                            }
                        } else {
                            return_msg('管理端-解锁礼品选择数设置不合法');
                            exit;
                        }
                    }
                    $gift_id = $_P['gift_id'];
                    //判断是否核销
                    $has_verify = $gift_item = db_get(t_shangjia_user_gift, ['themeid' => $themeid, 'order_id' => $record_item['id'], 'gift_id' => $gift_id]);
                    $check_worker = [];
                    //判断课程归属的商家与当前员工的商家是否一致
                    if ($has_verify['shangjiaid'] != $myworker['company']) {
                        return_msg('您无权核销此礼品，员工不归属于此礼品商家');
                        exit();
                    }
                    if ($has_verify && $has_verify['workerid']) {
                        $check_worker = db_get(t_worker, ['themeid' => $themeid, 'uid' => $has_verify['workerid']]);
                    }
                    //获取订单信息 姓名 手机号
                    //获取用户全部的赠品信息
                    $gift_list = EducationModel::getUserGift($themeid, $has_verify['shangjiaid'], '', 0, 50, '', '', '', $gift_id, 0, $record_item['id']);
                }
            } elseif ($op == 'course') {
                if ($myworker['level'] < 1 || $myworker['level'] > 3) {
                    return_msg('您无权访问');
                    exit;
                }
                $flag_id = $_P['flag_id'];
                $mobile = $_P['mobile'];
                if (!$mobile) {
                    return_msg('手机号绑定的订单不存在');
                    exit;
                }
                $record_item = db_get(t_record, ['themeid' => $themeid, 'mobile' => $mobile, 'status' => 1]);
                if (!$record_item) {
                    return_msg('该手机号绑定的订单不存在或未支付');
                    exit;
                }
                if (!$flag_id) {
                    return_msg('核销记录不存在，请检查后重试');
                    exit();
                }
                //判断是否核销
                $has_verify = db_get(t_shangjia_address_user_course, ['themeid' => $themeid, 'order_id' => $record_item['id'], 'id' => $flag_id]);
                //判断课程归属的商家与当前员工的商家是否一致
                if ($has_verify['shangjiaid'] != $myworker['company']) {
                    return_msg('您无权核销此礼品，员工不归属于此课程商家');
                    exit();
                }

                $sql = " SELECT a.id,a.shangjiaid,a.address,a.updated_at,a.status,a.workerid,b.avatar,b.nickname,b.username,b.mobile,c.name,
        c.top_img,d.name as shangjianame,e.fee,e.mobile as order_mobile,f.username as workenname FROM "
                    . tablename(t_shangjia_address_user_course) . " AS  a " .
                    " LEFT JOIN " . tablename(t_fans) . " AS b ON a.uid=b.uid and b.themeid=$themeid" .
                    " LEFT JOIN " . tablename(t_shangjia_course) . " AS c ON a.course_id=c.id and c.themeid=$themeid" .
                    " LEFT JOIN " . tablename(t_shangjia) . " AS d ON a.shangjiaid=d.id " .
                    " LEFT JOIN " . tablename(t_record) . " AS e ON a.order_id=e.id and  e.themeid=$themeid" .
                    " LEFT JOIN " . tablename(t_worker) . " AS f ON e.workerid=f.uid and f.themeid=$themeid" .
                    " WHERE a.themeid=$themeid and e.status=1 and a.id=$flag_id";

                $has_verify = db_find($sql);
                if (!$has_verify) {
                    return_msg('核销记录不存在，请检查后重试');
                    exit();
                } else {
                    //判断课程归属的商家与当前员工的商家是否一致
                    if ($has_verify['shangjiaid'] != $myworker['company'] && $myworker['level'] != 1) {
                        return_msg('您无权核销此课程，员工不归属于此课程商家');
                        exit();
                    }
                    if ($has_verify['status'] == 1) {
                        $check_worker = db_get(t_worker, ['themeid' => $themeid, 'uid' => $has_verify['workerid']]);
                    }
                }
            } elseif ($op == 'sure_verify') {
                if ($_G['ispost']) {
                    $where = ['id' => $_P['course_id'], 'themeid' => $themeid, 'status' => 0];
                    $data = ['status' => 1, 'workerid' => $myworker['uid']];
                    $res = EducationModel::editUserCourseAddress($where, $data);
                    if (!$res) {
                        return_json(1, '课程已核销或课程记录不存在，请检查后重试', '');
                    } else {
                        return_json(0, '课程核销成功', '');
                    }
                }
            } elseif ($op == 'gift_verify') {
                if ($_G['ispost']) {
                    $where = ['id' => $_P['gift_id'], 'themeid' => $themeid, 'can_use' => 1];
                    $data = ['workerid' => $myworker['uid']];
                    $res = EducationModel::updateUserGift($where, $data);
                    if (!$res) {
                        return_json(1, '礼品记录不存在，请检查后重试', '');
                    } else {
                        return_json(0, '礼品核销成功', '');
                    }
                }
            }
        }
        $return_clicent = get_defined_vars();
return $this->view('/education/verify', $return_clicent);
    }

    //分页加载数据
    public function spliceShangjiaList()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $theme = Theme::getThemeById($themeid);
        $_C = $config = Theme::getConfig($themeid);
        $system = $_S;
        $is_end = false;
        $page_index = max(1, intval($_P['page']));
        $page_size = 10;
        $total_sql = " select count(*) as cnt from " . tablename(t_shangjia) . " where id >0 and state=1 ";
        $total = db_find($total_sql)['cnt'];
        $max_page = ceil($total / $page_size);
        if ($page_index >= $max_page) {
            $is_end = true;
        }
        $item = EducationModel::getRewardByWhere(['themeid' => $themeid]);
        $other_config = json_decode($item['other_config'], true);
        $page_start = ($page_index - 1) * $page_size;
        $open_position = $other_config['open_position'];
        $shangjia_list = EducationModel::getShangjiaByPage($page_start, $page_size);
        if ($open_position) {
            $user_location = isset($_P['user_location']) ? $_P['user_location'] : '';
            $offset = $page_index - 1;
//            $shangjia_list = array_splice($shangjia_list,$offset,10);
            if ($user_location) {
                foreach ($shangjia_list as $key => $vv) {
                    if ($vv['mappoint'] && $vv['address'] && is_array($vv['mappoint'])) {
                        $distance_arr = [];
                        foreach ($vv['mappoint'] as $k1 => $v1) {
                            $distance_item = EducationModel::distance($v1, $user_location);
                            array_push($distance_arr, $distance_item);
                        }
                        $shangjia_list[$key]['min_distance'] = min($distance_arr);
                    }
                }
                $sort_filed = array_column($shangjia_list, 'min_distance');
                $shangjia_list = Ad::arraySort($shangjia_list, 'min_distance', 'asc');
            }
        }
        //机构视频
        $sj_list = [];
        //机构详情
        $sj_detail_list = [];
        foreach ($shangjia_list as $key => $val) {
            $sj_list_data = ['name' => $val['name'], 'logo' => $val['logo'], 'topimgs' => $val['imgs'],
                'video' => $val['videoyouku'], 'card_img' => $val['card_img'],
                'video_back_img' => $val['video_back_img'] ? $val['video_back_img'] : $val['logo']
            ];
            array_push($sj_list, $sj_list_data);
            //获取机构课程
            $sj_course_list = EducationModel::getCourseList($themeid, $val['id'], '', 0, 0, 1);
            $sj_course_total = EducationModel::getCourseTotal($themeid, $val['id']);
            array_push(
                $sj_detail_list,
                [
                    'name' => $val['name'], 'logo' => $val['logo'], 'topimgs' => $val['imgs'],
                    'card_img' => $val['card_img'], 'sj_id' => $val['id'],
                    'video' => $val['videoyouku'],
                    'video_back_img' => $val['video_back_img'] ? $val['video_back_img'] : $val['logo'],
                    'content' => $val['content'],
                    'address' => json_decode($val['address'], true),
                    'courses' => $sj_course_list,
                    'address_total' => count(json_decode($val['address'], true)),
                    'course_total' => $sj_course_total,
                    'order_total' => $val['order_total'],
                    'kefu' => ['avatar' => $val['logo'], 'mobile' => $val['mobile'], 'name' => $val['name'] . '客服']
                ]
            );
        }
        return_json(0, '', ['sj_list' => $sj_list, 'sj_detail_list' => $sj_detail_list, 'is_end' => $is_end]);
    }

    //获取商家详情
    public function getShangjiaDetailById()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $theme = Theme::getThemeById($themeid);
        $sj_id = $_P['sj_id'];
        $_C = $config = Theme::getConfig($themeid);
        $system = $_S;
        $is_end = false;
        $user_location = isset($_P['user_location']) ? $_P['user_location'] : '';

        $val = EducationModel::getShangjiaItem($sj_id);
        $distance_arr = [];

        $item = EducationModel::getRewardByWhere(['themeid' => $themeid]);
        $other_config = json_decode($item['other_config'], true);
        $open_position = $other_config['open_position'];
        if ($open_position){
            if (!$user_location) {
                $user_map_loc = EducationModel::getUserMapLoc($themeid, $uid);
                if ($user_map_loc) {
                    $user_location = $user_map_loc['lat_lng'];
                    $val['mappoint'] = json_decode($val['mappoint'], true);
                    if ($val['mappoint'] && $val['address'] && is_array($val['mappoint'])) {
                        foreach ($val['mappoint'] as $k1 => $v1) {
                            $distance_item = EducationModel::distance($v1, $user_location);
                            array_push($distance_arr, $distance_item);
                        }
                        $val['min_distance'] = min($distance_arr);
                    }else{
                        $val['min_distance']='';
                    }
                }
            }
        }
        //获取机构课程
        $sj_course_list = EducationModel::getCourseList($themeid, $val['id'], '', 0, 0, 1, 'show_sort', 2);
        foreach ($sj_course_list as $k => $v) {
            $sj_course_list[$k]['selected_num'] = $v['selected_num'] + EducationModel::getCourseFlagNum($themeid, $v['id']);
        }
        $sj_course_total = EducationModel::getCourseTotal($themeid, $val['id']);
        $temp_arr = [];
        $item = [
            'name' => $val['name'], 'logo' => $val['logo'], 'topimgs' => $val['imgs'],
            'card_img' => $val['card_img'],
            'video' => $val['videoyouku'],
            'video_back_img' => $val['video_back_img'] ? $val['video_back_img'] : $val['logo'],
            'content' => $val['content'],
            'address' => json_decode($val['address'], true),
            'courses' => $sj_course_list,
            'min_distance' => $val['min_distance'],
            'address_total' => count(json_decode($val['address'], true)),
            'course_total' => $sj_course_total,
            'order_total' => $val['order_total'],
            'kefu' => ['avatar' => $val['logo'], 'mobile' => $val['mobile'], 'name' => $val['name'] . '客服']
        ];
        array_push($temp_arr, $item);
        return_json(0, '', ['items' => $temp_arr]);


        $cache_key = 'item_' . $themeid . '_' . $sj_id;
        $has_cache = cache_load($cache_key);
        if (!$has_cache) {
            return_json(0, '', ['items' => $has_cache]);
        } else {
            $val = EducationModel::getShangjiaItem($sj_id);
            //获取机构课程
            $sj_course_list = EducationModel::getCourseList($themeid, $val['id'], '', 0, 0);
            foreach ($sj_course_list as $k => $v) {
                $sj_course_list[$k]['selected_num'] = $v['selected_num'] + EducationModel::getCourseFlagNum($themeid, $v['id']);
            }
            $sj_course_total = EducationModel::getCourseTotal($themeid, $val['id']);
            $temp_arr = [];
            $item = [
                'name' => $val['name'], 'logo' => $val['logo'], 'topimgs' => $val['imgs'],
                'card_img' => $val['card_img'],
                'video' => $val['videoyouku'],
                'video_back_img' => $val['video_back_img'] ? $val['video_back_img'] : $val['logo'],
                'content' => $val['content'],
                'address' => json_decode($val['address'], true),
                'courses' => $sj_course_list,
                'address_total' => count(json_decode($val['address'], true)),
                'course_total' => $sj_course_total,
                'order_total' => $val['order_total'],
                'kefu' => ['avatar' => $val['logo'], 'mobile' => $val['mobile'], 'name' => $val['name'] . '客服']
            ];
            array_push($temp_arr, $item);
            cache_write($cache_key, $temp_arr, 3600);
            return_json(0, '', ['items' => $temp_arr]);
        }
    }

    //获取商家列表
    public function getShangjiaList()
    {
        global $_P, $_G;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $theme = Theme::getThemeById($themeid);
        $_C = $config = Theme::getConfig($themeid);
        $kefu = ['qr_code' => $config['kfewm'], 'mobile' => $theme['mobile']];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $page = $_P['page'] ? (int)$_P['page'] : 1;
        $theme = Theme::getThemeById($themeid);
        $user_location = isset($_P['user_location']) ? $_P['user_location'] : '';

        $shangjia_list = EducationModel::getShangjiaList();
        foreach ($shangjia_list as $sk => $sv) {
            $shangjia_list[$sk]['address'] = json_decode($sv['address'], true);
            $shangjia_list[$sk]['mappoint'] = json_decode($sv['mappoint'], true);
        }
        $is_end = false;
        $offset = $page - 1;
        $max_page = ceil(count($shangjia_list) / 10);
        if ($page >= $max_page) {
            $is_end = true;
        }

        if ($user_location && $user_location != 'undefined,undefined') {
            foreach ($shangjia_list as $key => $vv) {
                if ($vv['mappoint'] && $vv['address'] && is_array($vv['mappoint'])) {
                    $distance_arr = [];
                    foreach ($vv['mappoint'] as $k1 => $v1) {
                        $distance_item = EducationModel::distance($v1, $user_location);
                        array_push($distance_arr, $distance_item);
                    }
                    $shangjia_list[$key]['min_distance'] = min($distance_arr);
                } else {
                    $shangjia_list[$key]['min_distance'] = 0;
                }
            }
            $sort_filed = array_column($shangjia_list, 'min_distance');
            $shangjia_list = Ad::arraySort($shangjia_list, 'min_distance', 'asc');
        }
        //机构视频
        $sj_list = [];
        //机构详情
        $sj_detail_list = [];
        foreach ($shangjia_list as $key => $val) {
            $sj_list_data = ['name' => $val['name'], 'logo' => $val['logo'], 'topimgs' => $val['imgs'],
                'video' => $val['videoyouku'],
                'video_back_img' => $val['video_back_img'] ? $val['video_back_img'] : $val['logo']
            ];
            array_push($sj_list, $sj_list_data);
            //获取机构课程
            $sj_course_list = EducationModel::getCourseList($themeid, $val['id'], '', 0, 0);
            $sj_course_total = EducationModel::getCourseTotal($themeid, $val['id']);
            $sj_xuni_order_total = EducationModel::getSjOrder($val, $themeid);
//            if ($sj_course_total>0){
            array_push(
                $sj_detail_list,
                [
                    'name' => $val['name'], 'logo' => $val['logo'], 'topimgs' => $val['imgs'],
                    'sj_id' => $val['id'],
                    'video' => $val['videoyouku'],
                    'video_back_img' => $val['video_back_img'] ? $val['video_back_img'] : $val['logo'],
                    'content' => $val['content'],
                    'address' => $val['address'],
                    'courses' => $sj_course_list,
                    'min_distance' => $val['min_distance'],
                    'address_total' => count($val['address']),
                    'course_total' => $sj_course_total,
                    'order_total' => $sj_xuni_order_total,
                    'kefu' => ['avatar' => 'https://kaifa5.yixuan.net/storage/shop/20211125/9ea396d559716c614db842d9fbb97670.png', 'mobile' => $val['mobile'], 'name' => $val['name'] . '客服']
                ]
            );
//            }
        }
        $offset = $offset * 10;
        $sj_detail_list = array_splice($sj_detail_list, $offset, 10);
        $item = EducationModel::getRewardByWhere(['themeid' => $themeid]);
        $other_config = json_decode($item['other_config'], true);
        $school_other_name = $other_config['school_other_name'];
        $course_other_name = $other_config['course_other_name'];
        $gift_other_name = $other_config['gift_other_name'];
        $edu_colors = json_decode($item['colors'], true);
        $show_buy_total = $other_config['show_buy_total'];
        if ($_G['ispost']) {
            $serviceList = '';
            foreach ($sj_detail_list as $index => $item) {
                $serviceList .= '<li style="background: ' . $edu_colors['shop_item_c'] . '" data-k="" data-sjid="' . $item['sj_id'] . '">' . PHP_EOL;
                $serviceList .= '<div class="serviceImg"><img src="' . $item['logo'] . '" ></div><div class="serviceTxt"><h2>' . $item['name'] . '</h2>';
                $serviceList .= '<p class="phoneNum">' . $item['kefu']['mobile'] . '</p>
                <p class="addInfor">' . $item['address'][0] . '</p>';
                if ($show_buy_total == 2) {
                    $serviceList .= '<p style="font-size: .24rem;color: #999999;line-height: .32rem;padding-top: .1rem">已购：' . $item['order_total'] . '</p>';
                }
                if ($user_location && $user_location != 'undefined,undefined') {
                    $serviceList .= '<p style="font-size: .24rem;color: #999999;line-height: .32rem;padding-top: .1rem">距离：' . $item['min_distance'] . 'km</p>';
                }
                $serviceList .= '</div><a href="javascript:void(0)" class="checkMore" data-k="' . $index . '" data-sjid="' . $item['sj_id'] . '"
               style="background: linear-gradient(90deg,' . $edu_colors['shop_card_c1'] . " -6.48%," . $edu_colors['shop_card_c2'] . " 97.21%)" . '">查看</a>
                </li>';
            }
            $res = [
                'append_html' => $serviceList,
                'is_end' => $is_end
            ];
            return_json(0, 'success', $res);
        } else {
            $return_clicent = get_defined_vars();
return $this->view('/education/sj_list', $return_clicent);
        }
    }

    /**
     * Desc:通过参数获取订单信息
     * Author:cbw
     * Email:17854288794@163.com
     * Time: 2023/7/5 14:27
     */
    public function getOrderInfoByParam()
    {
        global $_P, $_G, $_S, $_C;
        $system = $_S;
        $fromtype = $_P['from'];
        if ($fromtype != 'wxapp') {
            return_json(1, '非法请求');
        } else {
            $themeid = isset($_P['themeid']) ? $_P['themeid'] : '';
            $orderid = isset($_P['orderid']) ? $_P['orderid'] : '';
            $fans = $this->checkuser();
            if (!$themeid || !$orderid) {
                return_json(1, '请求参数缺失，请联系管理员');
            }
            $theme = Theme::getThemeById($themeid);
            $order_sql = " select * from " . tablename(t_order) . " where themeid=$themeid and id=$orderid ";
            $order = db_find($order_sql);
            if (!$order) {
                return_json(1, '未查询到您的订单');
            }
            $item = db_get(t_record, ['themeid' => $themeid, 'id' => $order['masterid']]);
            if (!$item) {
                return_json(1, '未查询到您的定单');
            }
            $orderInfo = [
                'fee' => $item['fee'],
                'avatar' => $item['avatar'],
                'username' => $item['username'],
                'mobile' => $item['mobile'],
                'tid' => $order['tid'],
            ];
            $check_worker = db_get(t_worker, ['themeid' => $themeid, 'uid' => $item['workerid']]);
            $workerInfo = [
                'worker_avatar' => $check_worker['avatar'],
                'worker_username' => $check_worker['username'],
                'worker_mobile' => $check_worker['mobile'],
            ];
            $user_flag = [];
            $user_flag = EducationModel::getUserCourseFlag($themeid, 0, '', 0, 0, '', '', $order['masterid'], 1, 0, 0);

            //获取员工
            //获取礼品信息
            //获取课程信息
            $format_info = [
                'orderInfo' => $orderInfo,
                'workerInfo' => $workerInfo,
                'flag' => $user_flag
            ];
            return_json(0, '', $format_info);
        }
    }

    //保存礼品跟课程
    public function saveTempCourseAndGift()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $theme = Theme::getThemeById($themeid);
        $system = $_S;
        $_C = $config = Theme::getConfig($themeid);
        $course_address = $_P['course_address'];
        $gift_ids = $_P['gift_ids'];
        $giftStr = $_P['giftStr'];
        $fans_item = db_get(t_fans, ['themeid' => $themeid, 'uid' => $fans['uid']]);
        $fans_other_info = json_decode($fans_item['other_info'], true);
        $new_be_info = [
            'giftStr' => $giftStr,
            'gift_ids' => $gift_ids,
            'course_address' => $course_address
        ];
        $fans_other_info['be_info'] = $new_be_info;
        $update_other_info = json_encode($fans_other_info);
        $where = ['themeid' => $themeid, 'uid' => $fans_item['uid']];
        $update = ['other_info' => $update_other_info];
        $res = db_update(t_fans, $update, $where);
        if (!$res) {
            return_json(1, '信息保存失败', '');
        } else {
            return_json(0, '信息保存成功', '');
        }
    }

    //小程序课程、礼品回显
    public function wxappPayConfirm()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $theme = Theme::getThemeById($themeid);
        $system = $_S;
        $_C = $config = Theme::getConfig($themeid);
        $fans_item = db_get(t_fans, ['themeid' => $themeid, 'pn_wxapp_openid' => $fans['openid']]);

        $fans_other_info = json_decode($fans_item['other_info'], true);;
        $gift_ids = $fans_other_info['be_info']['gift_ids'];
        $course_address = $fans_other_info['be_info']['course_address'];
        $giftStr = $fans_other_info['be_info']['giftStr'];


        $form = [
            ['title' => $config['nametext'], 'type' => 'txt', 'name' => 'nametext', 'val' => '', 'placeholder' => '请输入' . $config['nametext']],
            ['title' => $config['mobiletext'], 'type' => 'txt', 'name' => 'mobiletext', 'val' => '', 'placeholder' => '请输入' . $config['mobiletext']],
        ];
        if ($config['formtwo']) {
            $type = 'txt';
            switch ($config['formtwotype']) {
                case '1':
                    $type = 'number';
                    break;
                case '6':
                    $type = 'mobile';
                    break;
                case '7':
                    $type = 'date';
                    break;
                case '2':
                    $type = 'select';
                    break;
                case '3':
                    $type = 'radio';
                    break;
                default:
                    break;
            }
            $temp_arr = ['title' => $config['formtwo'], 'type' => $type, 'name' => 'formtwo', 'val' => $config['formtwooptions'], 'placeholder' => '请输入' . $config['formtwo']];
            array_push($form, $temp_arr);
        }
        if ($config['datetime']) {
            $type = 'txt';
            switch ($config['datetimetype']) {
                case '2':
                    $type = 'number';
                    break;
                case '6':
                    $type = 'mobile';
                    break;
                case '0':
                    $type = 'date';
                    break;
                default:
                    break;
            }
            $temp_arr = ['title' => $config['datetime'], 'type' => $type, 'name' => 'datetime', 'val' => '', 'placeholder' => '请输入' . $config['datetime']];
            array_push($form, $temp_arr);
        }
        if ($config['address']) {
            $type = 'txt';
            switch ($config['addresstype']) {
                case '1':
                    $type = 'number';
                    break;
                case '6':
                    $type = 'mobile';
                    break;
                case '7':
                    $type = 'date';
                    break;
                case '2':
                    $type = 'select';
                    break;
                case '3':
                    $type = 'radio';
                    break;
                default:
                    break;
            }
            $temp_arr = ['title' => $config['address'], 'type' => $type, 'name' => 'address', 'val' => $config['addressoptions'], 'placeholder' => '请输入' . $config['address']];
            array_push($form, $temp_arr);
        }
        if ($config['addinfo']) {
            $type = 'txt';
            switch ($config['addinfotype']) {
                case '2':
                    $type = 'number';
                    break;
                case '6':
                    $type = 'mobile';
                    break;
                case '0':
                    $type = 'date';
                    break;
                default:
                    break;
            }
            $temp_arr = ['title' => $config['addinfo'], 'type' => $type, 'name' => 'addinfo', 'val' => '', 'placeholder' => '请输入' . $config['addinfo']];
            array_push($form, $temp_arr);
        }
        if ($config['shops']) {
            $type = 'txt';
            $val = '';
            switch ($config['shopstype']) {
                case '2':
                    $type = 'number';
                    break;
                case '6':
                    $type = 'mobile';
                    break;
                case '7':
                    $type = 'date';
                    break;
                case '0':
                    $type = 'select';
                    $range_val = $config['options'];
                    if (!$config['gudingoptions']) {
                        $val = $range_val;
                    } else {
                        $guding_val = $config['gudingoptions'];
                        $val = array_merge($guding_val, $range_val);
                        $limit_config = ['min' => $config['shopsmin'], 'max' => $config['shopsmax']];
                    }
                    break;
                case '3':
                    $type = 'radio';
                    $val = $config['options'];
                    break;
                case '4':
                    $type = 'checkbox';
                    $range_val = $config['options'];
                    if (!$config['gudingoptions']) {
                        $val = $range_val;
                    } else {
                        $guding_val = $config['gudingoptions'];
                        $val = array_merge($guding_val, $range_val);
                        $limit_config = ['min' => $config['shopsmin'], 'max' => $config['shopsmax']];
                    }
                    break;
                case '5':
                    $type = 'shop_checkbox';
                    break;
                default:
                    break;
            }
            $temp_arr = ['title' => $config['shops'], 'type' => $type, 'name' => 'shops', 'val' => $val, 'placeholder' => '请输入' . $config['shops']];
            array_push($form, $temp_arr);
        }
        $coupon_item = EducationModel::getUserCouponInfo($themeid, $fans['uid']);
        $theme_status = EducationModel::checkThemeStatus($theme);


        $price = $old_price = $config['groupprice'];
        if ($coupon_item) {
            if ((float)$coupon_item['price'] < (float)$old_price) {
                $price = ($old_price - $coupon_item['price']);
            } else {
                $coupon_item['price'] = '';
            }
            $price_info = ['now_price' => $price, 'coupon' => $coupon_item['price']];
        } else {
            $price_info = ['now_price' => $price, 'coupon' => ''];
        }
        $setting = EducationModel::getRewardByWhere(['themeid' => $themeid]);
        $other_config = json_decode($setting['other_config'], true);
        $school_other_name = $other_config['school_other_name'];
        $course_other_name = $other_config['course_other_name'];
        $gift_other_name = $other_config['gift_other_name'];


        if ($course_address && $giftStr) {
            return_json(0, '', [
                'giftStr' => $giftStr, 'course_address' => $course_address, 'gift_ids' => $gift_ids,
                'form' => $form,
                'theme_status' => $theme_status,
                'price_info' => $price_info,
                'school_other_name' => $school_other_name,
                'course_other_name' => $course_other_name,
                'gift_other_name' => $gift_other_name,
                'jubf' => $theme['jubf'],
                'config' => $config
            ]);
        } else {
            return_json(1, '未获取到用户课程礼品记录', []);
        }
    }

    /**
     * Desc:更新定位缓存
     * User:cbw
     * Email:17854288794@163.com
     * Time: 2023/7/2 18:44
     */
    public function setUserLocationCache()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $cityname = $_P['cityname'] ? $_P['cityname'] : '';
        $lat = $_P['latlng']['lat'] ? $_P['latlng']['lat'] : '';
        $lng = $_P['latlng']['lng'] ? $_P['latlng']['lng'] : '';
        $poiaddress = $_P['poiaddress'] ? $_P['poiaddress'] : '';
        $poiname = $_P['poiname'] ? $_P['poiname'] : '';
        if ($lat && $lng && $poiaddress) {
            $format_data = [
                'cityname' => $cityname,
                'lat' => $lat,
                'lng' => $lng,
                'poiaddress' => $poiaddress,
                'poiname' => $poiname
            ];
            $res = EducationModel::setUserMapLoc($themeid, $uid, $format_data);
            if ($res) {
                return_json(0, '定位更新成功');
            }
        }
        return_json(1, '定位更新失败');
    }

    public function map()
    {
        global $_P, $_G, $_S;
        $fans = $this->checkuser();
        $uid = $fans['uid'];
        $themeid = $_P['themeid'];
        $fromuid = $_P['fromuid'];
        $system = $_S;
        $theme = Theme::getThemeById($themeid);
        $_C = $config = Theme::getConfig($themeid);
        $map_key = 'II4BZ-D7CRB-MQUUX-JP5JH-Y5NG7-UJBIE';
        $return_clicent = get_defined_vars();
return $this->view('/education/map', $return_clicent);
    }
}
